package com.zlh.hdfsfilesys.kit;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;


/**
 * 调用hdfs java api进行hdfs操作
 */
public class HadoopController {
    private String hdfsUri = "hdfs://192.168.48.128:9000/";
    private FileSystem fileSystem;

    public void hdget(String remote,String local) throws IOException {
        fileSystem.copyToLocalFile(new Path(remote),new Path(local));
    }

    public void hdput(String local,String remote) throws IOException {
        fileSystem.copyFromLocalFile(new Path(local),new Path(remote));
    }

    public void hdmkdir(String dir) throws IOException {
        fileSystem.mkdirs(new Path(dir));
    }
    public void hddel(String dir) throws IOException {
        fileSystem.delete(new Path(dir),true);
    }

    public FileStatus[] hdls(String dir) throws IOException{
        Path path = new Path(dir);

        FileStatus[] listStatus = fileSystem.listStatus(path);
        return listStatus;

    }
    public void getFileSystem() throws IOException, InterruptedException {
        Configuration configuration = new Configuration();

        fileSystem = FileSystem.get(URI.create(hdfsUri),configuration,"root");
    }




}
